MaJiang.prototype.canHuLaizi = function(oCards, cd) {
    var cards = [];
    var laizi = 0;
    for (var i = 0; i < oCards.length; i++) {
        if (this.isEqualHunCard(oCards[i])) {
            laizi++;
        }
        else {
            cards.push(oCards[i]);
        }
    }
    if (this.isEqualHunCard(cd)) {
        laizi++;
    }
    else if (cd) {
        cards.push(cd);
    }
    if ((cards.length + laizi + 1) % 3 != 0) {
        return false;
    }
    cards.sort(function(a, b) {
        return a - b;
    })
    // 依次删除一对牌做将，其余牌全部成扑则可胡
    for (var i = 0; i < cards.length; i++) {
        if (i > 0 && cards[i] == cards[i - 1]){
            continue; // 和上一次是同样的牌，略过不计算
        }
        if ((i + 1 < cards.length && cards[i] == cards[i + 1]) || laizi > 0) {
            var puCards = cards.slice();
            var puLaizi = laizi;
            puCards.splice(i, 1);
            if (puCards[i] == cards[i]) {
                puCards.splice(i, 1);
            }
            else {
                puLaizi--;
            }
            // logger.debug("=====canHuLaizi=====puCards:"+ puCards);
            if (this.isPu(puCards, puLaizi)) {
                return true;
            }
        }
    }
    if (laizi >= 2 && this.isPu(cards, laizi - 2)) {
        return true;
    }
    return false;

}
function isPu(cards, laizi){
    if (cards.length == 0) {
        return true;
    }
    // 若第一张是顺子中的一张 (理论上需判断下是条万筒)
    for (var first = cards[0] - 2; first <= cards[0]; first++) {
        if(first % 10 > 7 || (laizi == 0 && first < cards[0])) {
            continue;
        }
        var shunCount = 0;
        for (var i = 0; i < 3; i++) {
            if (cards.indexOf(first + i) >= 0) {
                shunCount++;
            }
       }
       if (shunCount == 3 || shunCount + laizi >= 3) {
            var puCards = cards.slice();
            var puLaizi = laizi;
            for (var i = 0; i < 3; i++) {
                var deletePos = puCards.indexOf(first + i);
                if (deletePos >= 0) {
                    puCards.splice(deletePos, 1);
                }
                else {
                    puLaizi--;
                }
            }
            if (isPu(puCards, puLaizi)) {
                return true;
            }
       }
    }
    // 若第一张是刻子中的一张
    var keziCount = 1;
    var keziCard = cards[0];
    if (cards[1] == keziCard) {
        keziCount++;
    }
    if (cards[2] == keziCard) {
        keziCount++;
    }
    if (keziCount == 3 || keziCount + laizi >= 3) {
        var puCards = cards.slice();
        var puLaizi = laizi;
        for (var i = 0; i < 3; i++) {
            var deletePos = puCards.indexOf(keziCard);
            if (deletePos >= 0) {
               puCards.splice(deletePos, 1);
            }
            else {
               puLaizi--;
            }
        }
        if (isPu( , puLaizi)) {
            return true;
        }
    }
    return false;
}